import 'package:flutter/material.dart';
import 'package:flutter_basic/pages/home/home_page.dart';
import 'package:flutter_basic/pages/cart/cart_page.dart';
import 'package:flutter_basic/pages/cate/cate_page.dart';
import 'package:flutter_basic/pages/user/user_page.dart';

class TabbarPage extends StatefulWidget {
  const TabbarPage({super.key});

  @override
  TabbarPageState createState() => TabbarPageState();
}

class TabbarPageState extends State<TabbarPage> {
  //激活索引
  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: IndexedStack(
        index: _currentIndex,
        children: const [HomePage(), CatePage(), CartPage(), UserPage()],
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white,
        currentIndex: _currentIndex,
        onTap: (value) {
          setState(() {
            _currentIndex = value;
          });
        },
        type: BottomNavigationBarType.fixed,
        unselectedFontSize: 12,
        unselectedItemColor: Colors.black,
        selectedFontSize: 12,
        selectedItemColor: Colors.red,
        items: [
          BottomNavigationBarItem(
            label: '首页',
            icon: Image.asset('assets/tabbar/ic_public_home_normal.png',
                width: 24, height: 24),
            activeIcon: Image.asset('assets/tabbar/ic_public_home_active.png',
                width: 24, height: 24),
          ),
          BottomNavigationBarItem(
              label: '分类',
              icon: Image.asset('assets/tabbar/ic_public_pro_normal.png',
                  width: 24, height: 24),
              activeIcon: Image.asset('assets/tabbar/ic_public_pro_active.png',
                  width: 24, height: 24)),
          BottomNavigationBarItem(
              label: '购物车',
              icon: Image.asset('assets/tabbar/ic_public_cart_normal.png',
                  width: 24, height: 24),
              activeIcon: Image.asset('assets/tabbar/ic_public_cart_active.png',
                  width: 24, height: 24)),
          BottomNavigationBarItem(
              label: '我的',
              icon: Image.asset('assets/tabbar/ic_public_my_normal.png',
                  width: 24, height: 24),
              activeIcon: Image.asset('assets/tabbar/ic_public_my_active.png',
                  width: 24, height: 24)),
        ],
      ),
    );
  }
}
